package com.aikon.wht.concurrent;

import java.util.concurrent.*;

/**
 * @author haitao.wang
 */
public class TestOfExecutorCompletionService {

    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(10);
        CompletionService cs = new ExecutorCompletionService(es);
        for (int i = 0; i < 10; i++) {
            cs.submit(() -> Thread.currentThread().getName());
        }
        try {
            for (int i = 0; i < 10; i++) {

                System.out.println(cs.take().get());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
